﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Templates_GalleryItem_Display : Acms.AcmsControls.TemplateUserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    public override void DataBind()
    {
        if (AcmsContext.CurrentPost != null && !(AcmsContext.CurrentPost is Acms.Bll.DummyPost))
        {
            lnk.Visible = false;
            //get the image
            var contentControl = AcmsContext.CurrentPost.FindPostControl("Image");
            if (contentControl != null)
            {
                var contentProperties = contentControl.GetProperties<Acms.AcmsControls.ImageContentControlProperties>();
                if (contentProperties != null && contentProperties.HasResource())
                {
                    lnk.Visible = true;
                    lnk.NavigateUrl = string.Format("~/file.aspx?id={0}&width=800&height=500", contentProperties.ResourceId);
                    if (AcmsContext.CurrentPost.ThumbnailId.HasValue)
                    {
                        lnk.ImageUrl = string.Format("~/file.aspx?id={0}&width={1}&height={2}", AcmsContext.CurrentPost.ThumbnailId, 200, 200);
                    }
                    else
                    {
                        lnk.ImageUrl = string.Format("~/file.aspx?id={0}&width={1}&height={2}", contentProperties.ResourceId, 200, 200);
                    }
                }
            }
        }
        else
        {
            lnk.NavigateUrl = "~/file.aspx?id=-1";
            lnk.ImageUrl = "~/file.aspx?id=-1&width=200&height=200";
        }
        base.DataBind();
    }
}
